/*
 * Collision.h
 *
 *  Created on: 08.12.2010
 *      Author: 123
 */

#ifndef COLLISION_H_
#define COLLISION_H_
#include "sMap.h"
extern sMap Map[2];
char colmapxy(int x, int y) { //test for a collision, note: map coordinates, not pixels!
	return Map[earth - 1].GetAbility(x, y);
}
bool collision_hor(int x, int y, int &tilecoordy) {
	int tilexpixels = x - (x % 32); //calculate the x position (pixels!) of the tiles we check against
	int testend = x + 31; //calculate the end of testing (just to save the x+w calculation each for loop)

	tilecoordy = y / 32; //calculate the y position (map coordinates!) of the tiles we want to test

	int tilecoordx = tilexpixels / 32; //calculate map x coordinate for first tile


	//loop while the start point (pixels!) of the test tile is inside the players bounding box
	while (tilexpixels <= testend) {
		if (colmapxy(tilecoordx, tilecoordy) == 1) //is a solid tile is found at tilecoordx, tilecoordy?
			return true;

		tilecoordx++; //increase tile x map coordinate
		tilexpixels += 32; //increase tile x pixel coordinate
	}

	return false;
}

//for explanation see CPlayer::collision_hor()
bool collision_ver(int x, int y, int &tilecoordx) {
	int tileypixels = y - (y % 32);
	int testend = y + 31;

	tilecoordx = x / 32;

	int tilecoordy = tileypixels / 32;

	while (tileypixels <= testend) {

		if (colmapxy(tilecoordx, tilecoordy) == 1)
			return true;

		tilecoordy++;
		tileypixels += 32;
	}

	return false;
}

#endif /* COLLISION_H_ */
